import SwiftUI

struct CultivationRingsView: View {
    @State private var techniqueProgress: Double = 0.7
    @State private var bodyProgress: Double = 0.8
    @State private var mindProgress: Double = 0.6
    
    var body: some View {
        ScrollView {
            VStack(spacing: 20) {
                headerView
                ringsView
                progressDetailsView
                recentActivitiesView
            }
            .padding()
        }
        .background(Color(.systemGroupedBackground))
        .edgesIgnoringSafeArea(.bottom)
    }
    // 再次
    private var headerView: some View {
        HStack {
            Text("修炼进度")
                .font(.largeTitle)
                .fontWeight(.bold)
            Spacer()
            Image(systemName: "person.circle")
                .font(.largeTitle)
        }
    }
    
    private var ringsView: some View {
        ZStack {
            CultivationRing(progress: mindProgress, color: .purple)
                .frame(width: 250, height: 250)
            CultivationRing(progress: bodyProgress, color: .green)
                .frame(width: 200, height: 200)
            CultivationRing(progress: techniqueProgress, color: .blue)
                .frame(width: 150, height: 150)
            VStack {
                Text("今日总进度")
                    .font(.headline)
                Text("\(Int((techniqueProgress + bodyProgress + mindProgress) / 3 * 100))%")
                    .font(.system(size: 44, weight: .bold, design: .rounded))
            }
        }
        .padding()
        .background(Color(.systemBackground))
        .cornerRadius(20)
        .shadow(radius: 5)
    }
    
    private var progressDetailsView: some View {
        VStack(spacing: 15) {
            ProgressRowView(title: "炼技", progress: techniqueProgress, color: .blue)
            ProgressRowView(title: "炼体", progress: bodyProgress, color: .green)
            ProgressRowView(title: "炼神", progress: mindProgress, color: .purple)
        }
        .padding()
        .background(Color(.systemBackground))
        .cornerRadius(15)
        .shadow(radius: 5)
    }
    
    private var recentActivitiesView: some View {
        VStack(alignment: .leading, spacing: 10) {
            Text("近期修炼记录")
                .font(.headline)
            
            ForEach(["炼技：剑法修习", "炼体：内功修炼", "炼神：冥想打坐"], id: \.self) { activity in
                HStack {
                    Image(systemName: activity.hasPrefix("炼技") ? "figure.martial.arts" :
                                      activity.hasPrefix("炼体") ? "figure.strengthtraining.traditional" : "brain.head.profile")
                        .foregroundColor(.blue)
                    VStack(alignment: .leading) {
                        Text(activity)
                            .font(.subheadline)
                            .fontWeight(.semibold)
                        Text("2小时 • 熟练度+5")
                            .font(.caption)
                            .foregroundColor(.secondary)
                    }
                    Spacer()
                    Text("今天")
                        .font(.caption)
                        .foregroundColor(.secondary)
                }
                .padding(.vertical, 8)
            }
        }
        .padding()
        .background(Color(.systemBackground))
        .cornerRadius(15)
        .shadow(radius: 5)
    }
}

struct CultivationRing: View {
    let progress: Double
    let color: Color
    
    var body: some View {
        ZStack {
            Circle()
                .stroke(color.opacity(0.2), lineWidth: 20)
            Circle()
                .trim(from: 0, to: CGFloat(progress))
                .stroke(color, style: StrokeStyle(lineWidth: 20, lineCap: .round))
                .rotationEffect(.degrees(-90))
                .animation(.easeInOut, value: progress)
        }
    }
}

struct ProgressRowView: View {
    let title: String
    let progress: Double
    let color: Color
    
    var body: some View {
        HStack {
            Text(title)
                .font(.headline)
            Spacer()
            Text("\(Int(progress * 100))%")
                .font(.subheadline)
                .foregroundColor(.secondary)
            ProgressView(value: progress)
                .progressViewStyle(LinearProgressViewStyle(tint: color))
                .frame(width: 100)
        }
    }
}

struct CultivationRingsView_Previews: PreviewProvider {
    static var previews: some View {
        CultivationRingsView()
    }
}

